
package cn.edu.shengda;

class PurchaseRequest{
    public double Amount;
    public int Number;
    public String Purpose;
}
class Approver{//审批者类
    public Approver(){ successor=null; }
    public void ProcessRequest(PurchaseRequest aRequest){
        if(successor!=null){successor.ProcessRequest(aRequest);}
    }
    public void setSuccessor(Approver aSuccessor){successor=aSuccessor;}
    private Approver successor;//上一级审批者
}
class Director extends Approver{
    @Override
    public void ProcessRequest(PurchaseRequest aRequest) {
        if(aRequest.Amount<50000){System.out.println("金额小于5万，主任审批");}
        else{
            System.out.println("【主任】大于5万，流转到上一级");
            super.ProcessRequest(aRequest); //调用父类的ProcessRequest方法
        }
    }
}
class VicePresident extends Approver{
    @Override
    public void ProcessRequest(PurchaseRequest aRequest) {
        if(50000<=aRequest.Amount && aRequest.Amount<100000){
            System.out.println("金额在5万和10万之间，副董事长审批");
        }
        else{
            System.out.println("【副董事长】大于10万，流转到上一级");
            super.ProcessRequest(aRequest); //调用父类的ProcessRequest方法
        }
    }
}
class President extends Approver{
    @Override
    public void ProcessRequest(PurchaseRequest aRequest) {
        if(100000<=aRequest.Amount && aRequest.Amount<500000){
            System.out.println("金额在10万和50万之间，董事长审批");
        }
        else{
            System.out.println("【董事长】大于50万，流转到上一级");
            super.ProcessRequest(aRequest); //调用父类的ProcessRequest方法
        }
    }
}
class Congress extends Approver{
    @Override
    public void ProcessRequest(PurchaseRequest aRequest) {
        if(aRequest.Amount >=500000){
            System.out.println("金额大于50万，例会审批");
        }
        else{
            System.out.println("【例会】状态异常");
            super.ProcessRequest(aRequest); //调用父类的ProcessRequest方法
        }
    }
}
public class rs {
    public static void main(String[] args){
        Director Larry=new Director();
        VicePresident Sam=new VicePresident();
        President Tammy=new President();
        Congress Meeting=new Congress();
        Larry.setSuccessor(Sam);
        Sam.setSuccessor(Tammy);
        Tammy.setSuccessor(Meeting);
        Meeting.setSuccessor(null);
        PurchaseRequest aRequest=new PurchaseRequest();
        aRequest.Amount=1900000;
        Larry.ProcessRequest(aRequest);
    }
}
